<?php
include('top.php');
require_once('pasmy/dbwaarden.php');

echo "<br><br>";

$mysql_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysql_id);
if(isset($_POST["toevoegen"])) {
	
	$naam = trim($_POST["naam"]);
	$voornaam = trim($_POST["voornaam"]);
	//echo "voornaam = $voornaam<br>";
	$geboren = trim($_POST["geboren"]);
	$plaats = trim($_POST["plaats"]);
	$rijbewijs = trim($_POST["rijbewijs"]);
	$sedert = trim($_POST["sedert"]);
	$soort = trim($_POST["soort"]);
	$id = trim($_POST["di"]);
	$langer = $naam . " " . $voornaam;
	$sql = "update chauffeurs set 
	`lang`='$langer',
	`kort`='$voornaam',
	`geboren`='$geboren',
	`plaats`='$plaats',
	`nrrijbewijs`='$rijbewijs',
	`sedert`='$sedert',
	`categorie`='$soort'
	where `id`= '$id'";
	//echo "sql = $sql";
	exit();
	$res = mysql_query($sql, $mysql_id);
		$fout = mysql_errno($mysql_id);
		if ($fout != 0) {
		echo "<font size='+2' color='#FF0000'>" . mysql_errno($mysql_id) . ": " . mysql_error($mysql_id) . "\n" . "</font>";
		mysql_close($mysql_id);
		echo '</body></html>';
		exit;
		}
		echo "<br /><br /><h2><div style='text-align: center'>Chauffeur werd aangepast</div></h2>";
	
}

if(isset($_GET["optie"])) {
	$optie = $_GET["optie"];
	$id = $_GET["nr"];

switch($optie) {
	
	case 1 :
		echo "<div style='text-align: center'><h2><font color='#0000FF'>Chauffeur aanpassen</font></h2></div>";
		$sql = "select * from chauffeurs where `id` = '$id'";
		$res = mysql_query($sql, $mysql_id);
		$fout = mysql_errno($mysql_id);
		if ($fout != 0) {
		echo "<font size='+2' color='#FF0000'>" . mysql_errno($mysql_id) . ": " . mysql_error($mysql_id) . "\n" . "</font>";
		mysql_close($mysql_id);
		echo '</body></html>';
		exit;
		}
		while ($row = mysql_fetch_row($res)) {
		$pnaam = explode(" ",$row[0]);
		$naam = $pnaam[0];
		$voornaam = $pnaam[1];
		$birth = $row[2];
		$place = $row[3];
		$permis = $row[4];
		$arbeit = $row[5];
		$di = $row[7];
		//echo "pnaam0 = $naam[0] en naam1 = $naam[1]<br>";
		//exit;
		}
		?>
<table align="center" width="40%">
<form action="chweg.php" method="post">
<tr>
<td><strong>Nom</strong></td><td><input type="text" name="naam" size="25" maxlength="25" value="<?php echo $naam;?>" /></td>
</tr>
<tr>
<td><strong>Pr&eacute;nom</strong></td><td><input type="text" name="voornaam" size="25" maxlength="25" value="<?php echo $voornaam;?>"/></td>
</tr>
<tr>
<td><strong>Date de naissance (JJ/MM/AAAA)</strong></td><td><input type="text" name="geboren" size="25" maxlength="25" value="<?php echo $birth;?>"/></td>
</tr>
<tr>
<td><strong>Lieu de naissance</strong></td><td><input type="text" name="plaats" size="25" maxlength="25" value="<?php echo $place;?>"/></td>
</tr>
<tr>
<td><strong>N&deg; permis</strong></td><td><input type="text" name="rijbewijs" size="25" maxlength="25" value="<?php echo $permis;?>"/></td>
</tr>
<tr>
<td><strong>Engager depuis (JJ/MM/AAAA)</strong></td><td><input type="text" name="sedert" size="25" maxlength="25" value="<?php echo $arbeit;?>" /></td>
</tr>
<tr>
<td><strong>Chauffeur de</strong></td><td><input type="radio" name="soort" value="porteur" checked="checked" /><strong>Porteur</strong>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="soort" value="semi" /><strong>Semi</strong></td>
</tr>
<tr><td colspan="2"><input type="hidden" name="di" value="<?php echo $di;?>" /></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><div style="text-align: center"><input type="submit" name="toevoegen" value="Ajuster" /></div></td></tr>
</form>
</table>


		<?php
	break;
	
	case 2 :
		echo "<div style='text-align: center'><h2><font color='#FF0000'>Chauffeur verwijderen</font></h2></div>";
		$sql = "delete from chauffeurs where `id` = '$id'";
		$res = mysql_query($sql, $mysql_id);
		$fout = mysql_errno($mysql_id);
		if ($fout != 0) {
		echo "<font size='+2' color='#FF0000'>" . mysql_errno($mysql_id) . ": " . mysql_error($mysql_id) . "\n" . "</font>";
		mysql_close($mysql_id);
		echo '</body></html>';
		exit;	 
		}
	echo "<br /><br /><h2><div style='text-align: center'>Chauffeur werd verwijderd !</div></h2>";
	}

}
else {

}
include('footer.php');
?>